#!/bin/bash
#desc: install keepalived
#author:haipenge
#date:2018.07.12
cd /tmp/
yum install -y libnl*
yum install -y libnfnetlink-devel zlib zlib-devel gcc gcc-c++ openssl openssl-devel openssh
wget http://www.keepalived.org/software/keepalived-1.3.5.tar.gz .
tar xvf keepalived-1.3.5.tar.gz
cd keepalived-1.3.5
./configure --prefix=/usr/local/keepalived
 make
 make install
cp keepalived-1.3.5/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
#需要修改的数据有以下几项：
# config: /etc/keepalived/keepalived.conf 文件的位置；
# Source configuration file (we set KEEPALIVED_OPTIONS there) 文件的位置。. /etc/sysconfig/keepalived
#修改为实际安装的文件路径，我的安装路径如下：

# config: /usr/local/keepalived/etc/keepalived/keepalived.conf
#. /usr/local/keepalived/etc/sysconfig/keepalived
#另外添加如下变量，并修改文件中相应的部分：
#keepalived=/usr/local/keepalived/sbin/keepalived
#keepalived_config=/usr/local/keepalived/etc/keepalived/keepalived.conf
#keepalived_pid=/usr/local/keepalived/run/keepalived.pid
chmod 755 /etc/init.d/keepalived
chkconfig –add keepalived
chkconfig keepalived on
chkconfig –list
systemctl enable keepalived.service #设置开机自动启动
#systemctl disable keepalived.service #取消开机自动启动
#systemctl start keepalived.service #启动服务
#systemctl restart keepalived.service #重启服务
#systemctl stop keepalived.service #停止服务
#systemctl status keepalived.service #查看服务状态
systemctl daemon-reload
exit 0
